<template>
  <div>
    <h2>编辑公告</h2>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>通知信息</span>
      </div>
      <div>
        <el-form ref="form" :model="announcement" label-width="80px">
          <el-form-item label="消息标题">
            <el-input v-model="announcement.title"></el-input>
          </el-form-item>
          <el-form-item label="消息内容">
            <el-input v-model="announcement.content" type="textarea"></el-input>
          </el-form-item>
          <el-form-item label="发布时间">
            <el-date-picker
                v-model="announcement.releaseTime"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="接收人">
            <el-link type="primary" @click="selectContactPersonFlag()">+选择联系人</el-link>
          </el-form-item>
          <el-form-item label="消息状态">
            {{this.announcement.status==0?"待发送":"已发布"}}
          </el-form-item>
          <el-form-item label="发布人">
            {{this.announcement.userId}}
          </el-form-item>
          <el-form-item label="编辑时间">
            {{this.announcement.editTime}}
          </el-form-item>
          <el-button type="danger" @click="removeAnnouncement()">删除</el-button>
          <el-button type="primary" @click="updateAnnouncement()">发布</el-button>
          <el-button @click="returnGonggao()">返回</el-button>
        </el-form>
      </div>
    </el-card>
  </div>
</template>
<script>
import axios from "axios";

export default {
  name: "updateVue",
  data(){
    return{
      id:null,
      announcement:{}
    }
  },
  created() {
    this.id=this.$route.query.id
    this.findByIdAnnouncement()
  },
  methods:{
    removeAnnouncement(){
      axios.delete(`http://localhost:8088/announcement/remove/${this.id}`).then(res=>{
        this.$router.push({path:'/xitong/gonggao'})
      })
    },
    updateAnnouncement(){
      axios.put("http://localhost:8088/announcement/",this.announcement).then(res=>{
        this.$router.push({path:'/xitong/gonggao'})
      })
    },
    returnGonggao(){
      this.$router.push({path:'/xitong/gonggao'})
    },
    findByIdAnnouncement(){
      axios.get(`http://localhost:8088/announcement/get/${this.id}`).then(res=>{
        this.announcement=res.data.data
      })
    }
  }
}
</script>
<style scoped>

</style>